package com.ruoyi.project.system.service.impl;

import com.ruoyi.project.system.domain.PerQuery;
import com.ruoyi.project.system.mapper.PerQueryMapper;
import com.ruoyi.project.system.service.IPerQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 病人问卷答案Service实现类
 */
@Service
public class PerQueryServiceImpl implements IPerQueryService {

    @Autowired
    private PerQueryMapper perQueryMapper;

    @Override
    public PerQuery selectByResId(String resId) {
        return perQueryMapper.selectByResId(resId);
    }

    @Override
    public List<String> selectAnswersByResId(String resId) {
        PerQuery perQuery = perQueryMapper.selectByResId(resId);
        List<String> answers = new ArrayList<>();

        if (perQuery != null) {
            // 按顺序添加非空答案
            if (perQuery.getAnswer1() != null && !perQuery.getAnswer1().isEmpty()) {
                answers.add(perQuery.getAnswer1());
            }
            if (perQuery.getAnswer2() != null && !perQuery.getAnswer2().isEmpty()) {
                answers.add(perQuery.getAnswer2());
            }
            if (perQuery.getAnswer3() != null && !perQuery.getAnswer3().isEmpty()) {
                answers.add(perQuery.getAnswer3());
            }
            if (perQuery.getAnswer4() != null && !perQuery.getAnswer4().isEmpty()) {
                answers.add(perQuery.getAnswer4());
            }
            if (perQuery.getAnswer5() != null && !perQuery.getAnswer5().isEmpty()) {
                answers.add(perQuery.getAnswer5());
            }
            if (perQuery.getAnswer6() != null && !perQuery.getAnswer6().isEmpty()) {
                answers.add(perQuery.getAnswer6());
            }
            if (perQuery.getAnswer7() != null && !perQuery.getAnswer7().isEmpty()) {
                answers.add(perQuery.getAnswer7());
            }
            // 如果有更多answer字段，继续添加...
        }

        return answers;
    }
}